package cn.pconline.autoclub.entity;

import cn.pconline.autoclub.util.EncodeUtils;
import cn.pconline.autoclub.util.WebUtils;
import com.alibaba.fastjson.JSONObject;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;
import org.gelivable.dao.Transient;

/**
 *
 * @author wanganning
 */
@Entity(tableName = "ac_user")
public class User {
    /**
     * 个人中心 性别  1-男*
     */
    public static final int MALE = 1;
    /**
     * 个人中心 性别  2-女*
     */
    public final static int FEMALE = 2;
    /**
     * 车友会 性别 0-男
     */
    public final static int CLUB_MALE = 0;
    /**
     * 车友会 性别 1 - 女
     */
    public final static int CLUB_FEMALE = 1;
    /*
     * 用户头像50X50
     */
    public static final int DEFAULT_AVATAR_SIZE = 50;
    @Id
    @Column(name = "user_id")
    private long uid;
    @Column(name = "create_at")
    private Date createAt;
    @Column(name = "username")
    private String username;
    @Column(name = "nickname")
    private String nickname;
    @Column(name = "truename")
    private String truename;
    @Column(name = "gender")
    private int gender;
    @Column(name = "province_id")
    private long provinceId;
    @Column(name = "province")
    private String province;
    @Column(name = "city_id")
    private long cityId;
    @Column(name = "city")
    private String city;
    @Column(name = "phone")
    private String phone;
    @Column(name = "vip")
    private int vip;
    @Column(name = "vip_info")
    private String vipInfo;
    @Column(name = "car_info")
    private String carInfo;
    @Column(name = "joined_club_count")
    private int joinedClubCount;
    //手机是否验证 默认未验证
    @Column(name = "phone_validated")
    private int phoneValidated;
    @Column(name = "birthday")
    private Date birthday;
    @Column(name = "token")
    private String token;//保存融云服务端得到的token
    @Column(name = "longitude")
    private double longitdue; //经度 
    @Column(name = "latitude")
    private double latitude; //纬度
    @Transient
    private double distance;//附近的人的距离
    @Column(name="email")
    private String email;//邮箱
    @Column(name="is_looked_admin_guide")
    private int isLookedAdminGuide;//是否看过会长引导图 0-否 1-是
    @Column(name="is_looked_member_guide")
    private int isLookedMemberGuide;//是否看过会员引导图 0-否 1-是
    @Column(name="uc_phone")
    private String ucPhone;//用于储存个人中心同步的联系电话
    /**
     * 绑定的手机号码
     */
    @Column(name="bind_phone")
    private String bindPhone;
    /**
     * 是否绑定过手机
     */
    @Column(name="is_sync_phone")
    private int isSyncdPhone;
    /**
     * 没看过车友会首页会长引导图
     */
    public static final int NO_LOOKED_ADMIN_GUIDE = 0;
    /**
     * 看过车友会首页会长引导图
     */
    public final static int LOOKED_ADMIN_GUIDE = 1;
    /**
     * 没看过车友会首页会员引导图
     */
    public final static int NO_LOOKED_MEMBER_GUIDE = 0;
    /**
     * 看过车友会首页会员引导图
     */
    public final static int LOOKED_MEMBER_GUIDE = 1;
    /**
     * 已经同步过绑定手机号码
     */
    public final static int IS_SYNC_PHONE = 1;
    /**
     * 没有同步过绑定手机号码
     */
    public final static int NO_SYNC_PHONE = 0;
    /**
     * 是认证会员
     */
    public final static int IS_VIP = 1;
    /**
     * 不是认证会员
     */
    public final static int NOT_VIP = 0;
    /**
     * 手机没验证
     */
    public final static int NOT_PHONE_VALIDATED = 0;
    /**
     * 手机已验证
     */
    public final static int IS_PHONE_VALIDATED = 1;
    
    public double getDistance() {
		return distance;
	}

	public void setDistance(double distance) {
		this.distance = distance;
	}

	public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public int getPhoneValidated() {
        return phoneValidated;
    }

    public void setPhoneValidated(int phoneValidated) {
        this.phoneValidated = phoneValidated;
    }

    public long getUid() {
        return uid;
    }

    public void setUid(long uid) {
        this.uid = uid;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getNickname() {
        if (nickname != null && nickname.length() > 0) {
            return nickname;
        }
        return username;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getTruename() {
        return truename;
    }

    public void setTruename(String truename) {
        this.truename = truename;
    }

    public int getGender() {
        return gender;
    }

    public void setGender(int gender) {
        this.gender = gender;
    }

    public long getProvinceId() {
        return provinceId;
    }

    public void setProvinceId(long provinceId) {
        this.provinceId = provinceId;
    }
    
    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }
    
    public long getCityId() {
        return cityId;
    }

    public void setCityId(long cityId) {
        this.cityId = cityId;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public int getVip() {
        return vip;
    }

    public void setVip(int vip) {
        this.vip = vip;
    }

    public String getVipInfo() {
        return vipInfo;
    }

    public void setVipInfo(String vipInfo) {
        this.vipInfo = vipInfo;
    }

    public String getCarInfo() {
        return carInfo;
    }

    public void setCarInfo(String carInfo) {
        this.carInfo = carInfo;
    }

    public int getJoinedClubCount() {
        return joinedClubCount;
    }

    public void setJoinedClubCount(int joinedClubCount) {
        this.joinedClubCount = joinedClubCount;
    }

    public String getBindPhone() {
        return bindPhone;
    }

    public void setBindPhone(String bindPhone) {
        this.bindPhone = bindPhone;
    }

    public int getIsSyncdPhone() {
        return isSyncdPhone;
    }

    public void setIsSyncdPhone(int isSyncdPhone) {
        this.isSyncdPhone = isSyncdPhone;
    }
    /**
     * 游客
     */
    public final static User ANONYMOUS = new User();

    static {
        ANONYMOUS.setUid(0l);
        ANONYMOUS.setUsername("游客");
        ANONYMOUS.setNickname("游客");
    }

    public boolean isComplete() {
        return StringUtils.isNotBlank(truename)
                && StringUtils.isNotBlank(province) && StringUtils.isNotBlank(city)
                && StringUtils.isNotBlank(phone) && phoneValidated == 1;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public double getLongitdue() {
        return longitdue;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLongitdue(double longitdue) {
        this.longitdue = longitdue;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }
    public JSONObject toJson(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userName", getUsername());
        jsonObject.put("userNikeName", getNickname());
        jsonObject.put("userPhone", getPhone());
        jsonObject.put("userCar", getCarInfo());
        jsonObject.put("userProvince", getProvince());
        jsonObject.put("userCity", getCity());
        jsonObject.put("userGener", getGender());
        jsonObject.put("trueName", getTruename());
        jsonObject.put("cityId", getCityId());
                 
        return jsonObject;        
    }    
    
    public JSONObject toJsonEncodeHTML(){
        JSONObject jsonObject = toJson();
        jsonObject.put("userName", EncodeUtils.encodeForHTMLFilterNull(getUsername()));
        jsonObject.put("userNikeName", EncodeUtils.encodeForHTMLFilterNull(getNickname()));
        jsonObject.put("userCar", EncodeUtils.encodeForHTMLFilterNull(getCarInfo()));
        jsonObject.put("userProvince", EncodeUtils.encodeForHTMLFilterNull(getProvince()));
        jsonObject.put("userCity", EncodeUtils.encodeForHTMLFilterNull(getCity()));      
        return jsonObject;
    }    
    
    public String getAvatar50(){
        return WebUtils.face(this.uid, 50);
    }
    
    public String getAvatar70(){
        return WebUtils.face(this.uid, 70);
    }

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public int getIsLookedAdminGuide() {
		return isLookedAdminGuide;
	}

	public void setIsLookedAdminGuide(int isLookedAdminGuide) {
		this.isLookedAdminGuide = isLookedAdminGuide;
	}

	public int getIsLookedMemberGuide() {
		return isLookedMemberGuide;
	}

	public void setIsLookedMemberGuide(int isLookedMemberGuide) {
		this.isLookedMemberGuide = isLookedMemberGuide;
	}

	public String getUcPhone() {
		return ucPhone;
	}

	public void setUcPhone(String ucPhone) {
		this.ucPhone = ucPhone;
	}
    
}
